﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using StreetlightGames.XnaEngine;
using System.Runtime.Serialization;

namespace StreetlightGames.SpaceShooter.Patterns
{
    [DataContract]
    public class Attack : Pattern
    {
        public Attack()
        {
        }

        public override void Start()
        {
            Ship.Velocity = new Vector3(0, 0, Ship.Speed);
            Ship.Velocity = VectorHelper.RotateY(Ship.Velocity, RandomHelper.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4));
            Ship.IsArmed = true;
            base.Start();
        }

        public override void Update(GameTime gameTime)
        {
            if (Ship.Position.Z > 100)
            {
                Ship.Position = new Vector3(Ship.Position.X, Ship.Position.Y, -1600);
            }
            if (Ship.Position.X > 400 && Ship.Velocity.X > 0)
            {
                NextPattern = new FlyInCircle(200, 1, -Ship.Heading + MathHelper.Pi);
                NextPattern.NextPattern = this;
                MoveToNextPattern(gameTime);
            }
            else if (Ship.Position.X < -400 && Ship.Velocity.X < 0)
            {
                NextPattern = new FlyInCircle(200, -1, -Ship.Heading + MathHelper.Pi);
                NextPattern.NextPattern = this;
                MoveToNextPattern(gameTime);
            }
            else
            {
                base.Update(gameTime);
            }
        }
    }
}
